package com.huanwang.commonlibrary.utils

import android.content.Context
import android.widget.Toast
import com.huanwang.commonlibrary.base.BaseApplication

/**
 * @author wang_hong_wei
 * @description 吐司工具类
 * @Date 2018-5-11
 */
object ToastUtils {
    private var mToast: Toast? = null

    /**
     * 显示对话框
     *
     * @param content 要显示的内容
     */
    fun showToast(context: Context?, content: String?) {
        if (mToast == null) {
            mToast = Toast.makeText(context, content, Toast.LENGTH_SHORT)
        } else {
            mToast!!.duration = Toast.LENGTH_SHORT
            mToast!!.setText(content)
        }
        mToast!!.show()
    }

    fun showToast(content: String?) {
        if (mToast == null) {
            mToast = Toast.makeText(BaseApplication.context, content, Toast.LENGTH_SHORT)
        } else {
            mToast!!.duration = Toast.LENGTH_SHORT
            mToast!!.setText(content)
        }
        mToast!!.show()
    }

    fun showLongToast(context: Context?, content: String?) {
        if (mToast == null) {
            mToast = Toast.makeText(context, content, Toast.LENGTH_LONG)
        } else {
            mToast!!.duration = Toast.LENGTH_LONG
            mToast!!.setText(content)
        }
        mToast!!.show()
    }

    fun showLongToast(content: String?) {
        if (mToast == null) {
            mToast = Toast.makeText(BaseApplication.context, content, Toast.LENGTH_LONG)
        } else {
            mToast!!.duration = Toast.LENGTH_LONG
            mToast!!.setText(content)
        }
        mToast!!.show()
    }
}